// pages/game/game-exchange-index/game-exchange-index.js
var api = require('../../../config/api.js');
var util = require('../../../utils/util.js');
var WxParse = require('../../../utils/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false, //弹出框显示
    swiper_index: 0,
    changeNum:0
  },


  // 计步器取值
  onChange(event) {
    this.setData({
      //兑换数量
      changeNum: event.detail
    })
  },



  // 弹出来控制
  exchange_to() {
    this.setData({
      show: true
    });
  },

  exchange_up() {
    this.setData({
      show: false
    });
  },

  toExchange: function(e) {
    if (this.data.changeNum > 0) {
      util.toClass("/pages/game/game-exchange-submit/game-exchange-submit", {
        productId: this.data.goodsInfo.productId,
        num: this.data.changeNum,
        bili:this.data.bili,
        prop: this.data.propInfo.propName,
        propid: this.data.propInfo.id,
        tradid: this.data.bean.tradeId,
        userpropid: this.data.bean.userPropId
      })

    } else {
      wx.showToast({
        title: "库存不足",
        icon: "none"
      })
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var id = options.id
    var bili=options.bili;
  
    this.setData({
      bili:bili
    })
    this.getData(id)
  },
  //swiper滑动监听
  onSwiperChange(e) {

    var swiper_index = e.detail.current;
    this.setData({
      swiper_index: swiper_index
    })
  },
  getData: function(id) {
    let that = this;
    util.gameRequest(api.PointExchangeGoodsDetail, {
      pramId: id
    }, 'get').then(function(res) {
      if (res.errno === 0) {

        that.setData({
          goodsInfo: res.data.goodsInfo,
          bean: res.data,
          propInfo: res.data.propInfo
        })
        var acrticle = res.data.goodsInfo.detail;
        WxParse.wxParse('article', 'html', acrticle, that, 5);
      } else {
        util.myToast(res.errmsg)
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})